<template>
  <div v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="12">
          <el-form-item :label="$t('出资人')" prop="investorId">
            <fund-lp-select
              v-model="form.investorId"
              :fund-id="form.fundId"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('出资人类型')" prop="investorsType">
            <dict-select
              v-model="form.investorsType"
              dictionary="fund_investor_type"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('计算基数-实缴金额') + $t('金额单位')" prop="beginningPaidInAmount">
            <Money v-model="form.beginningPaidInAmount" :placeholder="$t('期初实缴')" unit="w" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('计算基数-认缴金额') + $t('金额单位')" prop="subscribedAmount">
            <Money v-model="form.subscribedAmount" :placeholder="$t('期初认缴')" unit="w" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('计算基数-在投金额') + $t('金额单位')" prop="beginningReinvestedAmount">
            <Money v-model="form.beginningReinvestedAmount" :placeholder="$t('期初在投')" unit="w" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('管理费金额') + $t('金额单位')" prop="managementFee">
            <Money v-model="form.managementFee" :placeholder="$t('管理费金额')" unit="w" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <!--保存 取消按钮-->
      <save-btn has-permi="fund:expenseFeeDetail" />
    </div>
  </div>
</template>

<script>
import { saveFundManageFeeDetail, getFundManageFeeDetail } from '@/api/fund/manageFeeDetail/fundManageFeeDetail'
import FundLpSelect from '@/components/Select/fundLpSelect'
export default {
  components: {
    FundLpSelect
  },
  data() {
    return {
      // 表单参数
      form: {},
      // 遮罩层
      loading: false,
      // 表单校验
      rules: {
        investorId: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        investorsType: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        beginningPaidInAmount: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        subscribedAmount: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        beginningReinvestedAmount: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        managementFee: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ]
      }
    }
  },
  created() {
  },
  methods: {
    // 初始化数据
    init(data) {
      this.loading = true
      if (data != null && data.id !== undefined) {
        getFundManageFeeDetail(data.id).then(response => {
          this.form = response.data
          this.loading = false
        }).catch(() => {
          this.loading = false
        })
      } else {
        this.reset()
        this.loading = false
      }
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        managementId: undefined,
        fundId: undefined,
        investorId: undefined,
        beginningPaidInAmount: undefined,
        subscribedAmount: undefined,
        beginningReinvestedAmount: undefined,
        managementFee: undefined,
        remark: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined
      }
      this.resetForm('form')
    },
    // 取消按钮
    cancel() {
      this.$parent.$parent.formOpen = false
      this.$parent.$parent.reset()
    },
    // 关闭form页面
    closeForm() {
      // 关闭form页面遮罩层
      this.loading = false
      // 关闭form页面
      if (this.$parent.$parent.formOpen !== undefined) {
        this.$parent.$parent.formOpen = false
      }
      // 刷新list页面
      if (this.$parent.$parent.getList !== undefined) {
        this.$parent.$parent.getList()
        this.$parent.$parent.$parent.$parent.getList()
      }
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          this.loading = true
          saveFundManageFeeDetail(this.form).then(response => {
            if (response.code === 200) {
              this.msgSuccess(this.$t('保存成功'))
              this.closeForm()
            } else {
              this.msgError(response.msg)
            }
            this.loading = false
          })
        } else {
          this.locationError(document)
        }
      }).catch(() => {
        this.loading = false
      })
    }
  }
}
</script>
